package le.grand;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class FlightInfo {

	private Date day;
	private String departure;
	private String arrival;
	private String flightName;

	Map<String, HotelInfo> hotels = new HashMap<>();

	public void addHotel(HotelInfo hotelInfo) {
		hotels.put(hotelInfo.getHotelName(), hotelInfo);
	}

	public Map<String, HotelInfo> getHotels() {
		return hotels;
	}

	public Date getDay() {
		return day;
	}

	public void setDay(Date day) {
		this.day = day;
	}

	public String getDeparture() {
		return departure;
	}

	public void setDeparture(String departure) {
		this.departure = departure;
	}

	public String getArrival() {
		return arrival;
	}

	public void setArrival(String arrival) {
		this.arrival = arrival;
	}

	public String getFlightName() {
		return flightName;
	}

	public void setFlightName(String flightName) {
		this.flightName = flightName;
	}

	@Override
	public String toString() {
		return "FlightInfo [day=" + day + ", departure=" + departure + ", arrival=" + arrival
				+ ", flightName=" + flightName + "]";
	}

	public void append(FlightInfo anotherFlight) {
		if(this.equals(anotherFlight)) {
			System.err.println();
		}
		Collection<HotelInfo> vs = anotherFlight.hotels.values();
		for (HotelInfo hotelInfo : vs) {
			HotelInfo existingHotelInfo = this.hotels.get(hotelInfo.getHotelName());
			if (existingHotelInfo == null) {
				this.hotels.put(hotelInfo.getHotelName(), hotelInfo);
			} else {
				existingHotelInfo.append(hotelInfo);
			}
		}
	}

	public int getTotalNumOfChildren() {
		int k = 0;
		Collection<HotelInfo> hs = hotels.values();
		for (HotelInfo h : hs) {
			k += h.getNumOfChildren();
		}
		return k;
	}
	
	public int getTotalNumOfPassengers() {
		int k = 0;
		Collection<HotelInfo> hs = hotels.values();
		for (HotelInfo h : hs) {
			k += h.getTotalNumOfPassengers();
		}
		return k;
	}
	
}
